<template>
  <div class="admin-login">
    <h2>管理员登录</h2>
    <el-form :model="form" label-width="80px" @submit.prevent="handleLogin">
      <el-form-item label="账号">
        <el-input v-model="form.adminName" placeholder="请输入管理员账号" />
      </el-form-item>
      <el-form-item label="密码">
        <el-input v-model="form.adminPassword" type="password" placeholder="请输入密码" show-password />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" native-type="submit">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { adminLogin } from '@/api'
import { setToken } from '@/utils/storage'
import { ElMessage } from 'element-plus'

export default {
  data() {
    return {
      form: {
        adminName: '',
        adminPassword: ''
      }
    }
  },
  methods: {
    async handleLogin() {
      try {
        const { data } = await adminLogin(this.form)
        setToken(data)
        this.$router.push('/admin/dashboard')
        ElMessage.success('登录成功')
      } catch (error) {
        ElMessage.error(error.response?.data?.message || '登录失败')
      }
    }
  }
}
</script>

<style scoped>
.admin-login {
  max-width: 500px;
  margin: 100px auto;
  padding: 20px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.1);
}
</style>